import request from '@/api/request';
import type { VocabularyWord } from '@/types/vocabulary';

// 获取词语列表
export const getVocabularyList = (params: any) => {
  return request({
    url: '/api/vocabulary/list',
    method: 'get',
    params
  });
};

// 添加词语
export const addVocabulary = (data: VocabularyWord) => {
  return request({
    url: '/api/vocabulary/add',
    method: 'post',
    data
  });
};

// 更新词语
export const updateVocabulary = (data: VocabularyWord) => {
  return request({
    url: '/api/vocabulary/update',
    method: 'put',
    data
  });
};

// 删除词语
export const deleteVocabulary = (id: number) => {
  return request({
    url: `/api/vocabulary/delete/${id}`,
    method: 'delete'
  });
};

// 批量删除词语
export const batchDeleteVocabulary = (ids: number[]) => {
  return request({
    url: '/api/vocabulary/batch-delete',
    method: 'delete',
    data: ids,
  });
};

// 导入词语
export const importVocabulary = (data: FormData, moduleType: string) => {
  return request({
    url: `/api/vocabulary/import?moduleType=${moduleType}`,
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
};

// 下载词语导入模板
export const downloadVocabularyTemplate = () => {
  return request({
    url: '/api/vocabulary/downloadTemplate',
    method: 'get',
    responseType: 'blob', // 确保接收二进制数据
  });
};

// 获取词语详情
export const getVocabularyDetail = (id: number) => {
  return request({
    url: `/api/vocabulary/detail/${id}`,
    method: 'get'
  });
};

// 获取所有词语列表
export const getAllVocabularyList = () => {
  return request({
    url: '/api/vocabulary/all',
    method: 'get'
  });
};

// 获取练习词汇
export const getPracticeVocabularyList = (params: any) => {
  return request({
    url: '/api/vocabulary/practice',
    method: 'get',
    params
  });
};
